home *** CD-ROM | disk | FTP | other *** search
/ PD ROM 1 / PD ROM Volume I - Macintosh Software from BMUG (1988).iso / Stacks / Updates⁄New / TEXAS for BMUG / C progs / brwsr.2 ƒ / do_help⁄files.2.c < prev    next >
Encoding:
Text File  |  1987-10-07  |  3.5 KB  |  129 lines  |  [TEXT/KAHL]

  1. /* some functions to respond to various user inputs...
  2.  *  870806-13-... ^z
  3.  */
  4.  
  5. #include <stdio.h>            /* for FILE, printf(), etc. */
  6. #include <strings.h>        /* for strcpy(), etc. */
  7. #include <unix.h>            /* for exit(), etc. */
  8. #include <proto.h>            /* for function prototypes */
  9. #include "brwsr.h"            /* for various definitions */
  10. #include "brwsr.proto.h"    /* for my function prototypes */
  11.  
  12.  
  13. /* function to print out helpful information -- a command summary
  14.  * for the user....
  15.  */
  16.  
  17. void do_help ()
  18.   {
  19.     printf ("  ?        print this help\n");
  20.     printf ("  :        quit the program\n");
  21.     printf ("  :fnord   open document file 'fnord' for browsing\n");
  22.     printf ("  >grok    open notes file 'grok' and append output\n");
  23.     printf ("  >        close notes file\n");
  24.     printf ("  'DON.MAC append comment 'DON.MAC' to notes file\n");
  25.     printf ("  xyzzy    jump to 'XYZZY' in INDEX\n");
  26.     printf ("  \".123    jump to '.123' in INDEX\n");
  27.     printf ("  -17      back up 17 lines\n");
  28.     printf ("  -        back up one line\n");
  29.     printf ("  +0       print current line\n");
  30.     printf (" <return>  move down one line\n");
  31.     printf ("  +23      move down 23 lines\n");
  32.     printf ("  =        INDEX --> CONTEXT --> TEXT\n");
  33.     printf ("  ^        INDEX <-- CONTEXT <-- TEXT\n");
  34.     printf ("  .9       move down and print out 9 lines\n");
  35.     printf ("  *        create an empty working subset\n");
  36.     printf ("  **       fill the working subset (complete database)\n");
  37.     printf ("  &        add word-neighborhood to subset\n");
  38.     printf ("  &&       add sentence-neighborhood to subset\n");
  39.     printf ("  &&&      add paragraph-neighborhood to subset\n");
  40.     printf ("  ~        invert (logical NOT) entire working subset\n");
  41.     printf ("  ;        repeat previous command\n");
  42.   }
  43.  
  44.  
  45. /* function to handle a ":" command, to either quit the program or to
  46.  * open a new database for browsing.... display some amusing data
  47.  * about the file that is opened, if successful (total length in bytes,
  48.  * total number of words, and number of unique words in the file)...
  49.  */
  50.  
  51. void do_open (cmd)
  52.   char cmd[];
  53.   {
  54.       char qcmd[STRLEN];
  55.     extern FILE *doc_file;
  56.     extern long max_item[];
  57.     void destroy_subset (), open_files (), init_items ();
  58.     
  59.     if (cmd[1] == '\0')
  60.       {
  61.         printf ("Quit?\n");
  62.         gets (qcmd);
  63.         if (qcmd[0] == 'y' || qcmd[0] == 'Y')
  64.           {
  65.             printf ("Good-bye ... ^z\n");
  66.             exit ();
  67.           }
  68.         else
  69.           {
  70.             printf ("Cancelled!\n");
  71.             return;
  72.           }
  73.       }
  74.     
  75.     destroy_subset ();
  76.     open_files (cmd);
  77.     if (doc_file == NULL)
  78.         return;
  79.     init_items ();
  80.     printf ("File \"%s\" contains:\n", cmd + 1);
  81.     printf ("%9ld characters\n%9ld total words\n%9ld unique words\n",
  82.         max_item[TEXT] + 1, max_item[CONTEXT] + 1, max_item[INDEX] + 1);
  83.   }
  84.  
  85.  
  86. /* function to open or close a notes file ... copies of browser
  87.  * program output gets appended to that notes file as long as it
  88.  * is open, and the user may add comment strings with the '"' command ....
  89.  */
  90.  
  91. void do_redirection (cmd)
  92.   char cmd[];
  93.   {
  94.      extern FILE *notes_file;
  95.      FILE *fopen ();
  96.      
  97.     if (notes_file != NULL)
  98.          fclose (notes_file);
  99.      
  100.      if (cmd[1] == '\0')
  101.          return;
  102.  
  103.      if ((notes_file = fopen (cmd + 1, "a")) == NULL)
  104.        {
  105.         beep ();
  106.         printf ("Error opening notes file \"%s\"!\n", cmd + 1);
  107.         return;
  108.        }
  109.   }
  110.  
  111.  
  112. /* function to append a comment line to the notes_file... does the job
  113.  * for the '"' command....
  114.  */
  115.  
  116. void do_comments (cmd)
  117.   char cmd[];
  118.   {
  119.      extern FILE *notes_file;
  120.      
  121.      if (notes_file == NULL)
  122.        {
  123.         beep ();
  124.         printf ("No notes file open!\n");
  125.         return;
  126.        }
  127.      else
  128.         fprintf (notes_file, "%s\n", cmd + 1);
  129.   }